package com.seminario.spring.util;

import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

import com.seminario.spring.domain.Perfil;

@Component
public class ContextoUtilImpl implements ContextoUtil {

	@Override
	public Perfil getUsuarioActual() {
		Object attribute = RequestContextHolder.getRequestAttributes().getAttribute("loggedUser", RequestAttributes.SCOPE_SESSION);
		Perfil loggedUser = null;
		
		if(attribute!=null){
			if(attribute instanceof Perfil){
				loggedUser = (Perfil) attribute;
			}
		}
		
		return loggedUser;
	}

}
